package com.intelligent.system.auth.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligent.system.auth.dto.*;
import com.intelligent.system.auth.service.IMenuService;
import com.intelligent.system.common.response.ResultDO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
//import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "菜单管理")
@RestController
@RequestMapping("/api/menu")
@Validated
public class MenuController {

    @Resource
    private IMenuService menuService;

    @ApiOperation("获取菜单详情")
    @GetMapping("/{id}")
    public ResultDO<MenuDTO> getMenuInfo(
            @ApiParam("菜单ID") @PathVariable("id") @Valid Long id) {
        return menuService.getMenuById(id);
    }

    @ApiOperation("获取菜单列表")
    @PostMapping("/list")
    public ResultDO<Page<MenuDTO>> getMenuList(
            @ApiParam("查询参数") @RequestBody @Valid MenuQueryDTO param) {
        return menuService.getMenuList(param);
    }

    @ApiOperation("新增菜单")
    @PostMapping("/add")
    public ResultDO<?> addMenu(
            @ApiParam("菜单信息") @RequestBody @Valid MenuDTO param) {
        return menuService.addMenu(param);
    }

    @ApiOperation("修改菜单")
    @PostMapping("/update")
    public ResultDO<?> updateMenu(
            @ApiParam("菜单信息") @RequestBody @Valid MenuDTO param) {
        return menuService.updateMenu(param);
    }

    @ApiOperation("修改菜单显示状态")
    @PostMapping("/visible")
    public ResultDO<?> updateMenuVisible(
            @ApiParam("显示状态修改参数") @RequestBody @Valid MenuVisibleDTO param) {
        return menuService.updateMenuVisible(param.getMenuId(), param.getVisible());
    }

    @ApiOperation("删除菜单")
    @GetMapping("/delete/{id}")
    public ResultDO<?> deleteMenu( @ApiParam("菜单ID") @PathVariable("id") @Valid Long id) {
        return menuService.deleteMenuById(id);
    }
} 